<?php

namespace UI\Admin;

class Tag {
	public static function btn($type = 'submit', $url = '') {
		switch($type) {
			case 'submit' :
				return \Form::submit(array(
					'value' => 'Submit',
					'name' => '',
					'class' => 'btn btn-primary'
				));
				break;
			case 'update' :
				return \Form::submit(array(
					'value' => 'Update',
					'name' => '',
					'class' => 'btn btn-primary'
				));
				break;
			case 'back' :
				return \Form::button(array(
					'value' => 'Back',
					'name' => '',
					'class' => 'btn',
					'style' => 'margin-left: 5px;',
					'onclick' => "App.redirect('" . $url . "'); return false;"
				));
				break;
		}
	}

	public static function menus($menus = array(), $options = array()) {
		$out = '';
		$id = uniqid();
		if (is_array($menus) && count($menus)) {
			$out .= '<ul id="' . $id . '" class="fl nav nav-pills">';
			foreach ($menus as $menu) {
				$visibled = isset($menu['visibled']) ? $menu['visibled'] : false;
				if ($visibled) {
					continue;
				}

				$active = $menu['active'] === true ? ' class="active"' : '';
				$href = !empty($menu['url']) ? \Uri::create($menu['url']) : 'javascript:;';
				$out .= '<li' . $active . '><a href="' . $href . '" title="' . $menu['title'] . '">' . $menu['title'] . '</a>';

				if (isset($menu['items']) && is_array($menu['items']) && count($menu['items'])) {
					$out .= '<ul class="sub-nav">';
					foreach ($menu['items'] as $item) {
						$active = $item['active'] === true ? ' class="active"' : '';
						$href = isset($item['url']) ? \Uri::create($item['url']) : 'javascript:;';
						$out .= '<li' . $active . '><a href="' . $href . '" title="' . $item['title'] . '">' . $item['title'] . '</a></li>';
					}
					$out .= '</ul>';
				}

				$out .= '</li>';
			}
			$out .= '</ul>';
		}

		return $out;
	}

	public static function search_form($action = '') {
		$out = \Form::open(array(
			'action' => $action,
			'method' => 'get',
			'id' => 'search' . uniqid(),
			'class' => 'search-form none-ajax'
		));
		$out .= '<div class="row row-form">' . \Form::input(array(
			'name' => 's',
			'class' => 's',
			'placeholder' => 'Search...',
			'value' => \Input::get('s')
		));
		$out .= \Form::submit(array(
			'class' => 'submit-search',
			'name' => null,
			'value' => 'Search'
		)) . '</div>';
		$out .= \Form::close();

		return $out;
	}

	public static function side_menu($menus = array()) {
		$out = '';
		if (count($menus)) {
			$out .= '<ul class="side-menu">';
			foreach ($menus as $item) {
				$visibled = isset($item['visibled']) ? $item['visibled'] : false;
				if ($visibled) {
					continue;
				}

				$title = isset($item['title']) ? $item['title'] : '';
				if ($title != '') {
					$active = isset($item['active']) && $item['active'] === true ? ' class="active"' : '';
					$href = isset($item['url']) ? \Uri::create($item['url']) : 'javascript:;';
					$out .= '<li' . $active . '><a href="' . $href . '" title="' . $item['title'] . '">' . $item['title'] . '</a></li>';
				}
			}
			$out .= '</ul>';
		}

		return $out;
	}

}
